<?php

require_once 'src/model/mCliente.php';

class aCliente extends mCliente {
    /* datefomat ver data alua 06 
     * mysql : date_format(data_cad, '%s') as data_cad
     */
    protected $sqlInsert = "INSERT INTO cliente(nome, senha, cpf, telefone, endereco, login) VALUES ('%s','%s','%s','%s','%s','%s' )";
    protected $sqlUpdate = "UPDATE cliente SET nome='%s',senha='%s',cpf='%s',telefone='%s',endereco='%s',login='%s' WHERE idcliente = '%s'";
    protected $sqlSelect = "SELECT * FROM cliente WHERE 1=1 %s %s";
    protected $sqlDelete = "DELETE FROM cliente WHERE idcliente = '%s'";

    public function insert() {
        $sql = sprintf($this->sqlInsert, $this->getNome(), $this->getSenha(), 
                $this->getCpf(), $this->getTelefone(), $this->getEndereco(), 
                $this->getLogin());
        return $this->RunQuery($sql);
    }

    public function update() {
        $sql = sprintf($this->sqlUpdate, $this->getNome(), $this->getSenha(), 
                $this->getCpf(), $this->getTelefone(), $this->getEndereco(), 
                $this->getLogin(), $this->getIdcliente());
        return $this->RunQuery($sql);
    }

    public function delete() {
        $sql = sprintf($this->sqlDelete, $this->getIdcliente());
        return $this->RunQuery($sql);
    }
    
    public function select($where='', $order='') {
        $sql = sprintf($this->sqlSelect, $where, $order);
        return $this->RunSelect($sql);
    }
    
    public function load() {
        $rs = $this->select(sprintf("and idcliente='%s'", $this->getIdcliente()));
        $this->setIdcliente($rs[0]['idcliente']);
        $this->setNome($rs[0]['nome']);
        $this->setSenha($rs[0]['senha']);
        $this->setCpf($rs[0]['cpf']);
        $this->setTelefone($rs[0]['telefone']);
        $this->setEndereco($rs[0]['endereco']);
        $this->setLogin($rs[0]['login']);
        return $this;
    }
    
}
